package com.finger.forest.ui.patrol;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProviders;

import com.finger.forest.AlarmListActivity;
import com.finger.forest.CollectionActivity;
import com.finger.forest.HotCheckActivity;
import com.finger.forest.HotListActivity;
import com.finger.forest.MainActivity;
import com.finger.forest.PatrolReportActivity;
import com.finger.forest.PatrolStaticActivity;
import com.finger.forest.PatrolTraillActivity;
import com.finger.forest.R;
import com.finger.forest.base.CommonKey;
import com.finger.forest.utils.ClickUtils;
import com.finger.forest.utils.ToastUtils;
import com.finger.forest.utils.Utils;
import com.finger.forest.utils.encode.PrefsUtil;

public class PatrolFragment extends Fragment implements View.OnClickListener {

    /**
     * 巡护上报，巡护轨迹，热点核查，报警核查，信息采集，巡护统计
     */
    TextView patralReportTv, patrolTrailTv, hotCheckTv, alarmCheckTv, infoCollectionTv, patrolStaticTv;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {

        View root = inflater.inflate(R.layout.fragment_dashboard, container, false);

        //巡护上报
        patralReportTv = root.findViewById(R.id.tv_patrol_report);
        patralReportTv.setOnClickListener(this);

        //巡护轨迹
        patrolTrailTv = root.findViewById(R.id.tv_patrol_trail);
        patrolTrailTv.setOnClickListener(this);

        //热点核查
        hotCheckTv = root.findViewById(R.id.tv_hot_check);
        hotCheckTv.setOnClickListener(this);

        //报警核查
        alarmCheckTv = root.findViewById(R.id.tv_alarm_check);
        alarmCheckTv.setOnClickListener(this);

        //信息采集
        infoCollectionTv = root.findViewById(R.id.tv_info_collection);
        infoCollectionTv.setOnClickListener(this);

        //巡护统计
        patrolStaticTv = root.findViewById(R.id.tv_patrol_static);
        patrolStaticTv.setOnClickListener(this);

        return root;
    }

    @Override
    public void onClick(View v) {
        if (ClickUtils.isFastClick()) { //防止重复点击
            switch (v.getId()) {

                //跳转巡护上报
                case R.id.tv_patrol_report:
                    Intent intentPatrolReport = new Intent(getActivity(), PatrolReportActivity.class);
                    startActivity(intentPatrolReport);
                    break;

                //跳转巡护轨迹
                case R.id.tv_patrol_trail:
                    if (Utils.isLoginOffLine(getActivity())){
                        return;
                    }
                    Intent intentPatrolTrail = new Intent(getActivity(), PatrolTraillActivity.class);
                    startActivity(intentPatrolTrail);
                    break;

                //跳转热点核查
                case R.id.tv_hot_check:
                    if (Utils.isLoginOffLine(getActivity())){
                        return;
                    }
                    Intent intentHotCheck = new Intent(getActivity(), HotListActivity.class);
                    startActivity(intentHotCheck);
                    break;

                //跳转报警核查
                case R.id.tv_alarm_check:
                    if (Utils.isLoginOffLine(getActivity())){
                        return;
                    }
                    Intent intentAlarmCheck = new Intent(getActivity(), AlarmListActivity.class);
                    startActivity(intentAlarmCheck);
                    break;

                //跳转信息采集
                case R.id.tv_info_collection:
                    Intent intentInfoCollection = new Intent(getActivity(), CollectionActivity.class);
                    startActivity(intentInfoCollection);
                    break;

                //跳转巡护统计
                case R.id.tv_patrol_static:
                    if (Utils.isLoginOffLine(getActivity())){
                        return;
                    }
                    Intent intentPatrolStatic = new Intent(getActivity(), PatrolStaticActivity.class);
                    startActivity(intentPatrolStatic);
                    break;

                default:
                    break;
            }
        }
    }
}